package henu.graduation_design.onlineshop;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.TableRow;

public class ProfileActivity extends Activity {

	private TableRow cartRow;
	private TableRow orderRow;
	private TableRow historyRow;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_profile);
		cartRow = (TableRow) findViewById(R.id.profile_cart);
		cartRow.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(ProfileActivity.this,
						CartActivity.class);
				startActivity(intent);
			}
		});
		orderRow = (TableRow) findViewById(R.id.profile_order);
		orderRow.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(ProfileActivity.this,
						OrderActivity.class);
				intent.putExtra("flag", "new");
				startActivity(intent);
			}
		});
		historyRow = (TableRow) findViewById(R.id.profile_history_order);
		historyRow.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(ProfileActivity.this,
						OrderActivity.class);
				intent.putExtra("flag", "history");
				startActivity(intent);
			}
		});
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			new AlertDialog.Builder(this)
					// .setIcon(R.drawable.services)
					.setTitle("注意")
					.setMessage("确定要退出吗？")
					.setNegativeButton("取消",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
								}
							})
					.setPositiveButton("确定",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int whichButton) {
									finish();
								}
							}).show();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	}

}
